/*
 *  ColourWell.cpp
 *  Fridge
 *
 *  Created by Jeremy Abel on 7/8/12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

// Main header
#include "../Main.h"

// My Header
#include "ColourWell.h"

// Fridge
#include "../Controller/Controller_Main.h"
#include "../Controller/Controller_ModalColourPickerDialog.h"
#include "../Controller/Controller_ModalAddWidgetDialog.h"
#include "../Input.h"
#include "../MathsHelper.h"

ColourWell::ColourWell( Widget* pxParent ) : Panel( pxParent )
{
	
}

ColourWell::~ColourWell()
{
	
}

void ColourWell::Render()
{
	Panel::Render();
}

void ColourWell::Update()
{
	Panel::Update();

	Input* pxInput = Controller_Main::GetInputHandler();
	
	if( !pxInput )
	{
		return;
	}
	
	if( pxInput->MouseButtonDoubleClick( INPUT_MOUSE_BUTTON_LEFT ) && MouseInWidget() )
	{
		Controller_ModalColourPickerDialog::SetColour( m_uColour );
		Controller_ModalColourPickerDialog::SetCallback( DialogCallback_SetColour, this );
		Controller_ModalColourPickerDialog::Show();	
		
		m_bModified = true;
	}
}

void ColourWell::DialogCallback_SetColour( const Controller_ModalDialogResult eType, void* pxInstance )
{
	if( pxInstance )
	{
		reinterpret_cast< ColourWell* >( pxInstance )->_DialogCallback_SetColour();
	}
}

void ColourWell::_DialogCallback_SetColour()
{
	m_uColour = Controller_ModalColourPickerDialog::GetColour();
	m_bModified = true;
}

void ColourWell::SetValue( const u_int uValue )
{
	if( m_uColour == uValue )
	{
		return;
	}
	
	m_uColour = uValue;
	m_bModified = true;
}

// eof
